﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace ProcessBase.Models
{
    public class Order:V_MES_HX_MO
    {

        public int ID { get; set; }

        [DisplayName("原材料")]
        public string Materials { get; set; }//格式："材料编码1:型号1：名称1：批号1:数量1,材料编码2:型号2：名称2：批号2:数量2,..."

        [DisplayName("计划数量")]
        public double QuantityPlanned { get; set; }//计划数量=V_MES_HX_MO.nnum=>double

        [DisplayName("已入库数量")]
        public double QuantityDone { get; set; }

        [DisplayName("下单日期")]
        public DateTime OrderBillDate { get; set; }

        [DisplayName("关闭日期")]
        public DateTime? OrderCloseDate { get; set; }

        //已使用完工报告单行号（V_MES_HX_WR中以订单号，行号区分完工报告）
        public int UsedWanGongBaoGaoRowNo { get; set; }

        //完工报告主键
        public string WanGongBaoGaoID { get; set; }

        public void CopyFromMo(V_MES_HX_MO mo)
        {
            if (mo != null)
            {
                var typeMo = mo.GetType();
                var props=typeMo.GetProperties();
                var typeOrder = this.GetType();
                foreach(var prop in props)
                {
                    var val=prop.GetValue(mo);
                    var _prop = typeOrder.GetProperty(prop.Name);
                    _prop.SetValue(this, val);
                }

                //计划数量
                if (mo.nnum == null)
                {
                    this.QuantityPlanned = 0;
                }
                else
                {
                    this.QuantityPlanned = double.Parse(mo.nnum.ToString());
                }
                //下单日期
                DateTime date;
                bool success = DateTime.TryParse(mo.billdate, out date);
                this.OrderBillDate = success ? date.Date : new DateTime();
            }
            
        }

        public void CopyFrom(Order other)
        {
            Type type = this.GetType();
            var props = type.GetProperties();
            foreach (var prop in props)
            {
                if (prop.Name != "ID")
                {
                    prop.SetValue(this, prop.GetValue(other));
                }
            }
        }
    }
}
